#include <iostream>
#include "Sales_item.h"

using std::string;
using std::cin;
using std::cout;
using std::endl;

void Sales_item::set_sales()
{
	string str;
	unsigned int sold;
	double rev;
	
	cin >> str >> sold >> rev;
	isbn = str;
	units_sold = sold;
	revenue = rev;
}

void Sales_item::print_sales()
{
	cout << isbn << " " << units_sold << " " << revenue * units_sold << " "<< revenue << endl;
}

void Sales_item::merge_sales(const Sales_item& rhs)
{
	if(!same_isbn(rhs))
	{
		cout << "Error! mismatch isbn!" << endl;
		return;
	}
	
	unsigned int sold = units_sold + rhs.units_sold;
	double total = revenue * units_sold + rhs.revenue * units_sold;

	cout << isbn << " " << sold	<< " " << total << " " << total / sold << endl; 
}

int main()
{
	cout << "Enter a sale:" << endl;
	Sales_item si;
	si.set_sales();
	si.print_sales();
	cout << "Enter another sale:" << endl;
	Sales_item si2;
	si2.set_sales();
	cout << "Merge sales:" << endl;
	si.merge_sales(si2);

	return 0;
}
